<?php
/***************
* @Project	Warabi
* @Author	Feifei
* @Date		04/05/2009
***************/

/**this module gets and analyse
   *http request package,including
   *headers and bodys(xml)
   */

class wbHttpRequest{
	
	/** additional HTTP headers not prefixed with HTTP_ in $_SERVER superglobal */
	var $add_headers = array('X-WSSE');
	
	/** needed HTTP headers **/
	var $need_headers = array('Content-Type');

	/** http request headers **/
	var $headers = array();
	
	/** http request body **/
	var $body = "";

	/**
	 * Constructor
	 *
	 * @public
	 */
	 function wbHttpRequest($add_headers = false){
		$this->retrieveHeaders($add_headers);
		$this->retrieveBody();
	 }

	 /**
	 *get the http request headers
	 * @param $add_headers if gets the additional headers[Bool] 
	 */
	 function retrieveHeaders($add_headers = false){
			if($add_headers){
				$this->headers = array_merge($this->headers , $this->add_headers);
			}

			foreach($_SERVER as $key=>$val){
				if(strpos($key , 'HTTP_')===0 || in_array($key , $this->add_headers)){
					$key = str_replace('HTTP_' , '' , $key);
					$this->headers[$key] = $val;
				}
			}

			$this->headers['SERVER_PROTOCOL'] = isset($_SERVER['SERVER_PROTOCOL'])?$_SERVER['SERVER_PROTOCOL']:false;
	 }

	 /**
	 *get the http request body
	 **/
	 function retrieveBody(){
		$this->body = @file_get_contents('php://input');
	 }

	 /**
	 * return the result array
	 **/
	 function output(){
		 return array($this->headers , $this->body);
	 }
}

?>